import grails.util.GrailsUtil
import com.goal98.Person
import com.goal98.Authority

class BootStrap {

    def fixtureLoader
    def authenticateService

    def init = {servletContext ->

        final String env = GrailsUtil.environment
        final def adminPassword = authenticateService.encodePassword('lc541116')
        
        if (env == 'development' || env == 'test') {
            fixtureLoader.load('initDataDev')

            fixtureLoader.load {
                //Users start
                admin(Person) {
                    username = 'admin'
                    userRealName = 'Administrator'
                    passwd = adminPassword
                    email = 'liuchao36@gmail.com'
                    enabled = true
                }

                roleAdmin(Authority) {
                    authority = 'ROLE_ADMIN'
                    description = 'Admin Role'
                    people = [admin]

                }

                basicUserAdmin(Authority) {
                    authority = 'ROLE_BASIC_USER'
                    description = 'Basic User Role'
                }
                //Users end
            }
        }

    }
    def destroy = {
    }
} 